<template>
  <el-table :data="filterTest" style="width: 100%">
    <el-table-column label="日期" prop="date" />
    <el-table-column label="学号" prop="username" />
    <el-table-column label="名字" prop="stu_name" />
    <el-table-column label="结果" prop="answer" />
    <el-table-column align="right">
      <template #header>
        <el-input v-model="search" size="small" placeholder="Type to search" />
      </template>
      <!-- <template #default="scope">
        <el-button size="small" @click="handleEdit(scope.$index, scope.row)">Edit</el-button>
        <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">Delete</el-button>
      </template> -->
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { computed, ref } from "vue"
import { request } from "@/utils/service"
const search = ref("")
const filterTest = computed(() =>
  tests.value.filter((data) => !search.value || data.stu_name.toLowerCase().includes(search.value.toLowerCase()))
)
type test = {
  username: string
  stu_name: string
  date: string
  answer: string
}
const tests = ref<test[]>([])
request({
  url: "/test",
  method: "get"
}).then((resp) => {
  tests.value = resp.data.tests
  console.log(tests)
})
</script>
